package com.yifan.spring.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author YIFan
 * @Date 2021-7-26 10:11
 * @Version 1.0
 */
@Component
public class WebEventListener {
    Logger log = LoggerFactory.getLogger(WebEventListener.class);
    /**
     * 仅监听字段值为 zfan 时，类为 UserEvent.class 时
     */
//    @Async
    @EventListener(classes = UserEvent.class, condition = "#event.name == 'zfan'")
    public void listen(UserEvent event){
        // TODO
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("WebEventListener.listen===>["+event.getName()+"]");
    }

}
